﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PresentationWpf.Iteraror
{
   public class SelectedIterator:Iterator
    {
       int curentIndex;
       List<SelectedState> lista;
       public SelectedIterator(){
           lista = new List<SelectedState>();
           curentIndex =0;
       }
       
        public void Add(string State,String strategy)
        {
          
            if (curentIndex-1 == lista.Count )
            {
                lista.Add(new SelectedState() { State = State, Strategy = strategy });
                curentIndex++;
            }else{
            lista.Insert(curentIndex, new SelectedState() { State = State, Strategy = strategy });
            lista.RemoveRange(curentIndex , (lista.Count - 1) - curentIndex);
            }
            curentIndex++;
           
        }

        public SelectedState Next()
        {
            curentIndex++;
            if (curentIndex >= 0 && curentIndex<=lista.Count()-1)
            {
                if (lista[curentIndex] != null)
                {
                    return lista[curentIndex];
                    
                }
            }
            
            return null;
        }

        public SelectedState Undo()
        {

            if (curentIndex >= 1)
            {
                curentIndex--;
                if (curentIndex>=1&&lista[curentIndex - 1] != null)
                {
                    return lista[curentIndex - 1];
                }
            }
            
            return null;
        }
    }
}
